package com.abe.libcore.base.screen

import android.support.v4.app.Fragment
import com.abe.libcore.utils.CommonUtils

abstract class BScreenFragment : Fragment() {
    //是否需要自适应布局
    abstract fun isAutoZoom(): Boolean

    //是否正常设置标准宽度
    private var isScreenSetNormal: Boolean = false

    //获取标准宽度
    fun getStandardW(): Int {
        val designWidth = CommonUtils.getMetaData(context, "designWidth", 0)
        isScreenSetNormal = designWidth == null
        return if (isScreenSetNormal) designWidth as Int else 0
    }

    //获取缩放比例
    fun getScale(): Float {
        val displayMetrics = resources.displayMetrics
        val width = displayMetrics.widthPixels
        return if (isAutoZoom() && isScreenSetNormal) (width / getStandardW()).toFloat() else 1.0F
    }
}